Make the result of tty?
obtainable with flexible stdout
#87
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In mock testing for stdout,
StringIO.new
is sometimes used to redirect the output. In such cases, the assignment is done with$stdout = StringIO.new
, not the constantSTDOUT
.e.g., https://github.com/rubocop/rubocop/blob/v1.71.1/lib/rubocop/rspec/shared_contexts.rb#L154-L164
After assigning
StringIO.new
,$stdout.tty?
returnsfalse
, allowing the standard output destination to be switched during test execution.However, since
STDOUT.tty?
returnstrue
, a failure occurred in environments where the environment variablesRUBY_PAGER
orPAGER
are set.e.g., rubocop/rubocop#13784
To address this,
STDOUT
has been updated to$stdout
so that the result oftty?
can be flexibly overridden. A potential concern is that$stdout
, unlikeSTDOUT
, does not always represent the standard output at the time the Ruby process started. However, no concrete examples of issues related to this have been identified.STDOUT.tty?
is the logic of optparse introduced in #70. This PR replacesSTDOUT
with$stdout
throughout, based on the assumption that$stdout
is sufficient for use with optparse.